package com.sz.ruichar.controller.beans;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.sz.ruichar.entity.beans.TUserInfo;
import com.sz.ruichar.entity.model.constant.MsgException;
import com.sz.ruichar.interfs.beans.ITUserCheckInLogService;
import com.sz.ruichar.interfs.beans.ITUserInfoService;
import com.sz.ruichar.service.entity.model.result.ResultData;

@RestController
@RequestMapping("/act")
public class UserActionController 
{
    private static Logger log = LoggerFactory.getLogger(UserActionController.class);
    @Autowired
    private ITUserCheckInLogService userCheckInLogService;
    
    @PostMapping(value="checkIn")
    public ResultData getUserInfo(@RequestBody Map<String,String> param)
    {
    	if(null == param || param.isEmpty()){
    		return ResultData.error("error param");
    	}
    	Map<String,Object> timeResult = userCheckInLogService.getTodayCheckInTime(param.get("openid").toString());
		int checkTime = null == timeResult.get("checkTime")?0:Integer.valueOf(timeResult.get("checkTime").toString());
		if(checkTime>0){
			return ResultData.error("已签到");
		}
		Map<String,Object> result = new HashMap<>();
    	try {
    		result = userCheckInLogService.checkIn(param.get("openid").toString());
		} catch (Exception e) {
			
		}
    	return ResultData.success(result);
    }
    
    @GetMapping(value="isCheckIn")
    public  ResultData isCheckIn(String openid){
    	Map<String,Object> result = userCheckInLogService.getTodayCheckInTime(openid);
    	
    	return ResultData.success(result);
    }
    
    
    
    
    
}
